package com.itheima.controller;

import com.itheima.service.MenuService;
import com.itheima.util.ChildsDto;
import com.itheima.util.MenuAdd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menus")
public class MenuController {
    @Autowired
    private MenuService menuService;

    //菜单表集合查询
    @GetMapping
    public List<ChildsDto> list(){
        return menuService.list();
    }

    //菜单添加
    @PostMapping
    public void add(@RequestBody MenuAdd menuAdd){
        if(menuAdd!=null)
        menuService.add(menuAdd);
    }

    //根据id查询菜单
    @GetMapping("/{id}")
    public MenuAdd selById(@PathVariable Long id){
        return menuService.selById(id);
    }

    //根据id删除相关项
    @DeleteMapping("/{id}")
    public void delById(@PathVariable Long id){
        menuService.delById(id);
    }

    //根据id修改相关项
    @PutMapping("/{id}")
    public void upById(@PathVariable Long id,@RequestBody MenuAdd menuAdd){
        menuService.upById(id,menuAdd);
    }

}
